﻿using System;
using System.Collections.Generic;
using System.Text;


using Gx.Model;//实体
using Gx.Common;//通用类
using Gx.Model.Enums;
using System.Threading.Tasks;
using Gx.Model.Entity;
using Gx.Dal.Shared;

namespace Gx.Bll.Manage
{
    public class M_LogInfoBll
    {
        /// <summary>
        /// 添加操作日志
        /// </summary>
        /// <param name="url"></param>
        /// <param name="details">描述</param>
        /// <param name="message"></param>
        public void AddOptionsLog<T>(string url, string details, T message)
        {
            M_LogInfo model = new M_LogInfo()
            {
                AddTime = DateTime.Now,
                LogContenr = JsonHelper.SerializeObject(message),
                LogType = (int)LogType.操作日志,
                Url = url,
                Details = details
            };
            bool res = false;
            Task.Run(() => { res = AddM_LogInfo(model); });
        }

        /// <summary>
        /// 添加错误日志
        /// </summary>
        /// <param name="url"></param>
        /// <param name="message"></param>
        public void AddErrorLog(string url, string message)
        {
            M_LogInfo model = new M_LogInfo()
            {
                AddTime = DateTime.Now,
                LogContenr = message,
                LogType = (int)LogType.错误日志,
                Url = url
            };
            Task.Run(() => { AddM_LogInfo(model); });
        }


        private bool AddM_LogInfo(M_LogInfo model)
        {
            using (M_LogInfoDal dal = new M_LogInfoDal())
            {
                return dal.AddM_LogInfo(model);
            }
        }

        public ReturnModel<bool> DelM_LogInfo(int logId)
        {
            using (M_LogInfoDal dal = new M_LogInfoDal())
            {
                ReturnModel<bool> r = new ReturnModel<bool>()
                {
                    Code = (int)Code.操作成功,
                    Msg = "删除成功",
                };
                dal.DelM_LogInfo(logId);
                return r;
            }
        }

  
        private int GetM_LogInfoCount(string strWhere)
        {
            using (M_LogInfoDal dal = new M_LogInfoDal())
            {
                return dal.GetM_LogInfoCount(strWhere);
            }
        }

    }
}
